
class ASid implements SidInterface {

  private Serial  mSidPort;

  ASid( PApplet pParent, int pSidPortId )
  {
    this.mSidPort = new Serial(pParent, Serial.list()[pSidPortId], 9600);
  }


  void init()
  {
    updateInfoConsole("AtmegaSid: init");
    int vOut;
    vOut = 0xFF;
    this.mSidPort.write(vOut);
    delay(20);
    this.mSidPort.write(vOut);
    delay(100);
  }

  void stop()
  {
    updateInfoConsole("AtmegaSid: stop");
    this.write(4, 0);
    this.write(11, 0);
    this.write(18, 0);
  }




  void write( int pRegId, int pValue )
  {
    byte vValue = 0;
    
    if( pValue < 128 )
    {
      vValue = byte( pValue );
    }
    else
    {
      vValue = byte( pValue - 256 ); 
    }
    

    this.mSidPort.write( byte( pRegId ) );
    delay(2);

    this.mSidPort.write( vValue );
    delay(2);
    updateInfoConsole("AtmegaSid: Reg: " + pRegId + ", Value: " + pValue);
  }
}


